-
Notifications
You must be signed in to change notification settings - Fork 27.3k
feat(ngMock): allow mock $controller service to set up controller bindings #11239
Conversation
|
So: Should it be a shallow copy, as extend() currently does? This works better if the dictionary contains native values. |
…dings
Adds a new mock for the $controller service, in order to simplify testing using the
bindToController feature.
```js
var dictionaryOfControllerBindings = {
data: [
{ id: 0, phone: '...', name: '...' },
{ id: 1, phone: '...', name: '...' },
]
};
// When the MyCtrl constructor is called, `this.data ~= dictionaryOfControllerBindings.data`
$controller(MyCtrl, myLocals, dictionaryOfControllerBindings);
```
Closes angular#9425
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oftests --> of tests
|
@SonofNun15 / @cesarandreu would an API like this work for you guys? or do you prefer having the actual bindings set up |
|
That looks like exactly what I was hoping for. Bindings are not required from my perspective. Thanks so much! |
|
@caitp this works for me :D. I don't need bindings. I've basically gotten rid of big link functions in my directives. In my link function I'll setup watchers and call controller actions, and handle any kind of DOM transformation in as much isolation as possible. The controller is left responsible for tracking state and providing glue to services. |
|
okay --- @petebacondarwin if you aren't busy watching the conference, does this look good to you with the typo fixed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to be more strict and say toBe here? I know it doesn't really matter but since you asked the question about shallow copying I guess we could make it clear what the result of that was.
|
LGTM, merging with tweaked docs. Do we want to change the unit test WRT #11239 (comment) ? |
…dings
Adds a new mock for the $controller service, in order to simplify testing using the
bindToController feature.
```js
var dictionaryOfControllerBindings = {
data: [
{ id: 0, phone: '...', name: '...' },
{ id: 1, phone: '...', name: '...' },
]
};
// When the MyCtrl constructor is called, `this.data ~= dictionaryOfControllerBindings.data`
$controller(MyCtrl, myLocals, dictionaryOfControllerBindings);
```
Closes #9425
Closes #11239
sounds good to me |
…dings
Adds a new mock for the $controller service, in order to simplify testing using the
bindToController feature.
```js
var dictionaryOfControllerBindings = {
data: [
{ id: 0, phone: '...', name: '...' },
{ id: 1, phone: '...', name: '...' },
]
};
// When the MyCtrl constructor is called, `this.data ~= dictionaryOfControllerBindings.data`
$controller(MyCtrl, myLocals, dictionaryOfControllerBindings);
```
Closes angular#9425
Closes angular#11239
|
This is great! |
|
Thanks @thelgevold |
…dings
Adds a new mock for the $controller service, in order to simplify testing using the
bindToController feature.
```js
var dictionaryOfControllerBindings = {
data: [
{ id: 0, phone: '...', name: '...' },
{ id: 1, phone: '...', name: '...' },
]
};
// When the MyCtrl constructor is called, `this.data ~= dictionaryOfControllerBindings.data`
$controller(MyCtrl, myLocals, dictionaryOfControllerBindings);
```
Closes angular#9425
Closes angular#11239
Adds a new mock for the $controller service, in order to simplify testing using the
bindToController feature.
Closes #9425